#include<iostream>
#include<pthread.h>
using namespace std;

pthread_mutex_t mux=PTHREAD_MUTEX_INITIALIZER;

void* ptf(void *para)
{
	pthread_mutex_lock(&mux);
	cout<<"thread1"<<endl;
	pthread_mutex_unlock(&mux);
	pthread_exit((void*)1);
}

void* ptf2(void* para)
{	
	pthread_mutex_lock(&mux);
	cout<<"thread2"<<endl;	
	pthread_mutex_unlock(&mux);
	pthread_exit((void*)2);
}

int main()
{
	pthread_t tid,tid2;
	pthread_mutex_lock(&mux);
	int ret=pthread_create(&tid,nullptr,ptf,nullptr);
	int ret2=pthread_create(&tid2,nullptr,ptf2,nullptr);

	if(ret || ret2){
		cout<<"error"<<endl;
		exit(1);
	}
	
	cout<<"thread create finished"<<endl;
	pthread_mutex_unlock(&mux);
	void *retv,*retv2;
	pthread_join(tid,&retv);
	pthread_join(tid2,&retv2);
}
